/**
 *
 */
package de.cbf.cam.dsa.person.base;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.beans.IndexedPropertyChangeEvent;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.util.ArrayList;
import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import de.cbf.cam.dsa.person.entities.PersonBaseDSA;
import de.cbf.cam.dsa.person.entities.PersonSpecialsDSA;
import de.cbf.cam.dsa.rcp.model.entities.CultureDSA;
import de.cbf.cam.dsa.rcp.model.entities.MonthDSA;
import de.cbf.cam.dsa.rcp.model.entities.MonthDSAEnum;
import de.cbf.cam.dsa.rcp.model.entities.ProfessionDSA;
import de.cbf.cam.dsa.rcp.model.entities.RaceDSA;
import de.cbf.cam.dsa.services.interfaces.rcp_provider.IServiceDSAProviderMonths;
import de.cbf.cam.dsa.services.interfaces.rcp_provider.IServiceDSARCPFinder;
import de.cbf.cam.dsa.services.interfaces.rcp_provider.exceptions.CultureNotFoundException;
import de.cbf.cam.dsa.services.interfaces.rcp_provider.exceptions.EntityNotFoundException;
import de.cbf.cam.dsa.services.interfaces.rcp_provider.exceptions.ProfessionNotFoundException;
import de.cbf.cam.dsa.services.interfaces.rcp_provider.exceptions.RaceNotFoundException;
import de.cbf.util.entities.FloatString;
import de.cbf.util.number_generator.RandomNumberGenerator;
import de.cbf.util.number_generator.interfaces.IProbabilitySpan;
import de.cbf.util.uuidheader.entities.EntityWeighted;
import de.cbf.util.uuidheader.entities.UUIDReference;
import de.cbf.util.uuidheader.util.EntityWeightedList;

/**
 * @author Surfer
 *
 */
public class ControllerPersonBaseDSA {
	private static final Log logger = LogFactory.getLog(ControllerPersonBaseDSA.class);

	protected CompositePersonBaseDSA composite;

	protected PersonBaseDSA originalPerson;
	protected PersonBaseDSA changedPerson;

	protected IServiceDSARCPFinder		rcpFinder;
	protected IServiceDSAProviderMonths providerMonths 		;

	protected void addModelListeners(PersonBaseDSA person) {
		if(person == null){
			return;
		}
		person.getPropertyChangeSupport().addPropertyChangeListener(modelListener);
	}

	protected void removeModelListeners(PersonBaseDSA person) {
		if(person == null){
			return;
		}
		person.getPropertyChangeSupport().removePropertyChangeListener(modelListener);
	}

	protected void addUIListeners(CompositePersonBaseDSA composite) {
		if(composite == null){
			return;
		}
		composite.addUIListener(personBaseUIL);
	}

	protected void removeUIListeners(CompositePersonBaseDSA composite) {
		if(composite == null){
			return;
		}
		composite.removeUIListener(personBaseUIL);
	}

	public boolean hasChanges(){
		return originalPerson.equals(changedPerson);
	}

	public void conductSave(){
		try {
			originalPerson = (PersonBaseDSA) changedPerson.clone();
		} catch (CloneNotSupportedException e) {
			logger.error("Error in saving changedPerson",e);
		}
	}

	/**
	 *
	 */
	public void openLooksWindow() {
		logger.debug("opening LooksWindow");
	}

	/**
	 *
	 */
	public void openCharacterSpecialWindow() {
		logger.debug("opening CharacterSpecialsWindow");
	}

	protected void initalizeComposite(){
		if(composite != null){
			composite.setAmmountOfPossibleBirthdays(0);
			//months
			List<MonthDSA> possibleMonths = providerMonths.getMonthsDSA();
			updatePossibleMonths(possibleMonths);
			//
			updatePossibleRCP(changedPerson);
		}
		updateAll();
	}




	/**
	 *
	 */
	protected void updateAll() {
		//port checks, updating is nonsense if model or view is missing
		if(composite == null){
			return;
		}
		if(changedPerson == null){
			return;
		}

	}

	protected void updatePropertyInView(int index,Object newValue){
		if(composite == null){
			return;
		}
		switch (index) {
		case PersonBaseDSA.PI_TITLE:
			updateTitle(newValue);
			break;
		case PersonBaseDSA.PI_FIRST_NAME:
			updateFirstName(newValue);
			break;
		case PersonBaseDSA.PI_NAME_ADD:
			updateNameAdd(newValue);
			break;
		case PersonBaseDSA.PI_SUR_NAME:
			updateSurName(newValue);
			break;
		case PersonBaseDSA.PI_BIRTH_DAY:
			updateBirthDay(newValue);
			break;
		case PersonBaseDSA.PI_BIRTH_MONTH:
			updateBirthMonth(newValue);
			break;
		case PersonBaseDSA.PI_BIRTH_YEAR:
			updateBirthYear(newValue);
			break;
		case PersonBaseDSA.PI_RACE:
			updateRace(newValue);
			break;
		case PersonBaseDSA.PI_CULTURE:
			updateCulture(newValue);
			break;
		case PersonBaseDSA.PI_PROFESSION:
			updateProfession(newValue);
			break;
		case PersonBaseDSA.PI_HEIGTH:
			updateHeigth(newValue);
			break;
		case PersonBaseDSA.PI_WEIGHT:
			updateWeight(newValue);
			break;
		case PersonBaseDSA.PI_CHARACTER_SPECIALS:
			updateCharacterSpecials(newValue);
			break;
		case PersonBaseDSA.PI_EYES:
			updateLooks();
			break;
		case PersonBaseDSA.PI_HAIR:
			updateLooks();
			break;
		case PersonBaseDSA.PI_LOOKS:
			updateLooks();
			break;
		default:
			logger.error("unknown property changed: "+index+", value: "+newValue );
			break;
		}
	}

	/**
	 * @param newValue
	 */
	protected void updateFirstName(Object newValue) {
		if(composite == null){
			return;
		}
		if (newValue instanceof String ) {
			String string = (String) newValue;
			composite.setFirstName(string);
		}else{
			logger.error("wrong Type of firstName: "+newValue.getClass().getCanonicalName());
		}
	}

	/**
	 * @param newValue
	 */
	protected void updateNameAdd(Object newValue) {
		if (newValue instanceof String) {
			String string = (String) newValue;
			composite.setNameAdd(string);
		}else{
			logger.error("wrong Type of nameAdd: "+newValue.getClass().getCanonicalName());
		}
	}

	/**
	 * @param newValue
	 */
	protected void updateSurName(Object newValue) {
		if (newValue instanceof String) {
			String string = (String) newValue;
			composite.setSurName(string);
		}else{
			logger.error("wrong Type of surName: "+newValue.getClass().getCanonicalName());
		}
	}

	/**
	 * @param newValue
	 */
	protected void updateBirthDay(Object newValue) {
		if (newValue instanceof Integer) {
			Integer value = (Integer) newValue;
			composite.setSelectedBirthDay(value);
		}else{
			logger.error("wrong Type of birthDay: "+newValue.getClass().getCanonicalName());
		}
	}

	/**
	 * @param newValue
	 */
	protected void updateBirthMonth(Object newValue) {
		if (newValue instanceof String) {
			String value = (String) newValue;
			composite.setSelectedMonth(value);
		}else{
			logger.error("wrong Type of birthMonth: "+newValue.getClass().getCanonicalName());
		}
	}

	/**
	 * @param newValue
	 */
	protected void updateBirthYear(Object newValue) {
		if (newValue instanceof String) {
			String value = (String) newValue;
			composite.setBirthYear(value);
		}else{
			logger.error("wrong Type of birthYear: "+newValue.getClass().getCanonicalName());
		}
	}

	/**
	 * @param newValue
	 */
	protected void updateRace(Object newValue) {
		if (newValue instanceof String) {
			String value = (String) newValue;
			composite.setSelectedRace(value);
		}else{
			logger.error("wrong Type of chosenRace: "+newValue.getClass().getCanonicalName());
		}
	}

	/**
	 * @param newValue
	 */
	protected void updateCulture(Object newValue) {
		if (newValue instanceof String) {
			String value = (String) newValue;
			composite.setSelectedCulture(value);
		}else{
			logger.error("wrong Type of chosenCulture: "+newValue.getClass().getCanonicalName());
		}

	}

	/**
	 * @param newValue
	 */
	protected void updateProfession(Object newValue) {
		if (newValue instanceof String) {
			String value = (String) newValue;
			composite.setSelectedProfession(value);
		}else{
			logger.error("wrong Type of chosenProfession: "+newValue.getClass().getCanonicalName());
		}
	}

	/**
	 * @param newValue
	 */
	protected void updateHeigth(Object newValue) {
		if (newValue instanceof String) {
			String value = (String) newValue;
			composite.setHeigth(value);
		}else{
			logger.error("wrong Type of heigth: "+newValue.getClass().getCanonicalName());
		}
	}

	/**
	 * @param newValue
	 */
	protected void updateWeight(Object newValue) {
		if (newValue instanceof String) {
			String value = (String) newValue;
			composite.setWeight(value);
		}else{
			logger.error("wrong Type of weight: "+newValue.getClass().getCanonicalName());
		}
	}

	/**
	 * @param newValue
	 */
	protected void updateCharacterSpecials(Object newValue) {
		if (newValue instanceof PersonSpecialsDSA) {
			PersonSpecialsDSA value = (PersonSpecialsDSA) newValue;

			String valueString = value.toString();
			composite.setCharacterSpecials(valueString);
		}else{
			logger.error("wrong Type of characterSpecials: "+newValue.getClass().getCanonicalName());
		}
	}


	/**
	 */
	protected void updateLooks() {
		//TODO get looks/eyes/hair from person to generate looks
		composite.setLooks("<aggregated Looks from looks eyes hair etc");
	}

	protected void updateTitle(Object newValue) {
		if (newValue instanceof String) {
			String title = (String) newValue;
			composite.setTitle(title);
		}else{
			logger.error("Wrong type provided for title: "+newValue.getClass().getCanonicalName());
		}
	}

	protected void updatePossibleMonths(List<MonthDSA> possibleMonths) {
		List<String> months = new ArrayList<String>();
		for (MonthDSA monthDSA : possibleMonths) {
			months.add(monthDSA.getName());
		}
		composite.setPossibleMonths(months);
	}


	protected void updatePossibleRCP(PersonBaseDSA person){
		RaceDSA personRace = resolveRace(person);
		CultureDSA personCulture = resolveCulture(person);
		ProfessionDSA personProfession = resolveProfession(person);
		//races
		try {
			//will find all races, when culture and profession null
			EntityWeightedList possibleRaces = rcpFinder.findRacesBy(personCulture,personProfession);
			updatePossibleRaces(possibleRaces);
		} catch (RaceNotFoundException e) {

		}
		//cultures
		try{
			//will find all cultures, when race and profession null
			EntityWeightedList possibleCultures = rcpFinder.findCulturesBy(personRace,personProfession);
			updatePossibleCultures(possibleCultures);
		}catch(CultureNotFoundException e){

		}
		//professions
		try{
			//will find all professions, when race and culture null
			EntityWeightedList possibleProfessions = rcpFinder.findProfessionsBy(personRace,personCulture);
			updatePossibleProfessions(possibleProfessions);
		}catch(ProfessionNotFoundException e){

		}
	}

	protected RaceDSA resolveRace(PersonBaseDSA person){
		if(person == null){
			logger.debug("no person set");
			return null;
		}
		UUIDReference personRace = person.getRace();
		if(personRace == null){
			logger.debug("race of person not set");
			return null;
		}
		RaceDSA result;
		try {
			result = (RaceDSA)  rcpFinder.resolveEntity(
					personRace, IServiceDSARCPFinder.PROVIDER_RACE);
		} catch (EntityNotFoundException e) {
			logger.error("race with id: "+personRace+" not found!");
			return null;
		}
		return result;
	}

	protected CultureDSA resolveCulture(PersonBaseDSA person) {
		if(person == null){
			logger.debug("no person set");
			return null;
		}
		UUIDReference personCulture = person.getCulture();
		if(personCulture == null){
			logger.debug("culture of person not set");
			return null;
		}
		CultureDSA result;
		try {
			result = (CultureDSA)  rcpFinder.resolveEntity(
					personCulture, IServiceDSARCPFinder.PROVIDER_CULTURE);
		} catch (EntityNotFoundException e) {
			logger.error("culture with id: "+personCulture+" not found!");
			return null;
		}
		return result;
	}

	protected ProfessionDSA resolveProfession(PersonBaseDSA person) {
		if(person == null){
			logger.debug("no person set");
			return null;
		}
		UUIDReference personProfession = person.getCulture();
		if(personProfession == null){
			logger.debug("culture of person not set");
			return null;
		}
		ProfessionDSA result;
		try {
			result = (ProfessionDSA) rcpFinder.resolveEntity(
					personProfession, IServiceDSARCPFinder.PROVIDER_PROFESSION);
		} catch (EntityNotFoundException e) {
			logger.error("culture with id: "+personProfession+" not found!");
			return null;
		}
		return result;
	}


	/**
	 * @param possibleCultures
	 */
	protected void updatePossibleRaces(EntityWeightedList possibleRaces) {
		List<FloatString> races = new ArrayList<FloatString>();
		Double max = RandomNumberGenerator.calculateSum(new ArrayList<IProbabilitySpan>(possibleRaces));
		for (EntityWeighted entityWeighted : possibleRaces) {
			if (entityWeighted.getEntity() instanceof RaceDSA) {
				RaceDSA entity = (RaceDSA) entityWeighted.getEntity();
				float percentage = RandomNumberGenerator.calculatePercentage(entityWeighted.getProbabilitySpan(),max);
				//
				races.add(new FloatString(entity.getName(),percentage));
			}
		}
		composite.setPossibleRaces(races);
	}



	/**
	 * @param possibleCultures
	 */
	protected void updatePossibleCultures(EntityWeightedList possibleCultures) {
		List<FloatString> cultures = new ArrayList<FloatString>();
		Double max = RandomNumberGenerator.calculateSum(new ArrayList<IProbabilitySpan>(possibleCultures));
		for (EntityWeighted entityWeighted : possibleCultures) {
			if (entityWeighted.getEntity() instanceof CultureDSA) {
				CultureDSA entity = (CultureDSA) entityWeighted.getEntity();
				float percentage = RandomNumberGenerator.calculatePercentage(entityWeighted.getProbabilitySpan(),max);
				//
				cultures.add(new FloatString(entity.getName(),percentage));
			}
		}
		composite.setPossibleCultures(cultures);
	}

	/**
	 * @param possibleCultures
	 */
	protected void updatePossibleProfessions(EntityWeightedList possibleProfessions) {
		List<FloatString> professions = new ArrayList<FloatString>();
		Double max = RandomNumberGenerator.calculateSum(new ArrayList<IProbabilitySpan>(possibleProfessions));
		for (EntityWeighted entityWeighted : possibleProfessions) {
			if (entityWeighted.getEntity() instanceof ProfessionDSA) {
				ProfessionDSA entity = (ProfessionDSA) entityWeighted.getEntity();
				Float percentage = RandomNumberGenerator.calculatePercentage(entityWeighted.getProbabilitySpan(),max);
				//
				professions.add(new FloatString(entity.getName(),percentage));
			}
		}
		composite.setPossibleProfessions(professions);
	}

	protected void changeAll(){
		if(composite == null){
			return;
		}
		if(changedPerson == null){
			return;
		}
//		changeTitle(composite.getTitle());
//		changeFirstName(composite.getFirstName());
//		changeNameAdd(composite.getNameAdd());
//		changeSurName(composite.getSurName());
		changeBirthMonth(composite.getSelectedMonth());
		changeBirthDay(composite.getSelectedBirthDay());
		changeBirthYear(composite.getBirthYear());
		changeHeigth(composite.getHeigth());
		changeWeight(composite.getWeight());
		changeRace(composite.getSelectedRace());
		changeCulture(composite.getSelectedCulture());
		changeProfession(composite.getSelectedProfession());
	}

	protected void changeBirthDay(Integer newBirthDay) {
		changedPerson.setBirthday(newBirthDay);
	}

//	protected void changeTitle(String title) {
//		changedPerson.setTitle(title);
//	}
//
//	/**
//	 * @param firstName
//	 */
//	protected void changeFirstName(String firstName) {
//		changedPerson.setFirstName(firstName);
//	}
//
//	/**
//	 * @param nameAdd
//	 */
//	protected void changeNameAdd(String nameAdd) {
//		changedPerson.setNameAdd(nameAdd);
//	}
//
//	/**
//	 * @param surName
//	 */
//	protected void changeSurName(String surName) {
//		changedPerson.setSurName(surName);
//	}

	/**
	 * @param selectedMonth
	 */
	protected void changeBirthMonth(String selectedMonth) {
		MonthDSAEnum[] months = MonthDSAEnum.values();
		for (int i = 0; i < months.length; i++) {
			MonthDSAEnum month = months[i];
			if(month.getName().equals(selectedMonth)){
				changedPerson.setBirthmonth(month);
				return;
			}
		}
	}

	/**
	 * @param birthYear
	 */
	protected void changeBirthYear(String birthYear) {
		try{
			long year = Long.parseLong(birthYear);
			changedPerson.setBirthyear(year);
		}catch (NumberFormatException exc) {
			logger.error("BirthYear not parsable: "+birthYear);
		}
	}

	/**
	 * @param heigth
	 */
	protected void changeHeigth(String heigth) {
		try{
			float heigthFloat = Float.parseFloat(heigth);
			changedPerson.setHeight(heigthFloat);
		}catch (NumberFormatException exc) {
			logger.error("Heigth not parsable: "+heigth);
		}
	}

	/**
	 * @param weight
	 */
	protected void changeWeight(String weight) {
		try{
			float weightFloat = Float.parseFloat(weight);
			changedPerson.setWeight(weightFloat);
		}catch (NumberFormatException exc) {
			logger.error("Weight not parsable: "+weight);
		}
	}

	/**
	 * @param selectedRace
	 * TODO when loading race put them in map<String(name),UUIDReference>, set uuid ref to person
	 */
	protected void changeRace(String selectedRace) {
		try {
			List<EntityWeighted> allEntities = rcpFinder.findRacesBy(null, null);
			List<RaceDSA> races = new ArrayList<RaceDSA>();
			for (EntityWeighted entityWeighted : allEntities) {
				if (entityWeighted.getEntity() instanceof RaceDSA) {
					RaceDSA race = (RaceDSA) entityWeighted.getEntity();
					races.add(race);
				}else{
					logger.error("Non-Culture provided: "+entityWeighted.getEntity());
				}
			}
			for (RaceDSA raceDSA : races) {
				if(selectedRace.equals(raceDSA.getName())){
					changedPerson.setRace(UUIDReference.extractUUIDReference(raceDSA));
					updatePossibleRCP(changedPerson);
					break;
				}
			}
			logger.error("RACE "+selectedRace+" not found");
		} catch (RaceNotFoundException e) {
			logger.error("no races found, check configuration");
		}
	}

	/**
	 * @param selectedCulture
	 */
	protected void changeCulture(String selectedCulture) {
		try {
			List<EntityWeighted> allEntities = rcpFinder.findCulturesBy(null, null);
			List<CultureDSA> cultures = new ArrayList<CultureDSA>();
			for (EntityWeighted entityWeighted : allEntities) {
				if (entityWeighted.getEntity() instanceof CultureDSA) {
					CultureDSA culture = (CultureDSA) entityWeighted.getEntity();
					cultures.add(culture);
				}else{
					logger.error("Non-Culture provided: "+entityWeighted.getEntity());
				}
			}
			for (CultureDSA cultureDSA : cultures) {
				if(selectedCulture.equals(cultureDSA.getName())){
					changedPerson.setCulture(UUIDReference.extractUUIDReference(cultureDSA));
					updatePossibleRCP(changedPerson);
					break;
				}
			}
			logger.error("CULTURE "+selectedCulture+" not found");
		} catch (CultureNotFoundException e) {
			logger.error("no cultures found, check configuration");
		}
	}

	/**
	 * @param selectedProfession
	 */
	protected void changeProfession(String selectedProfession) {
		try {
			List<EntityWeighted> allEntities = rcpFinder.findProfessionsBy(null, null);
			List<ProfessionDSA> professions = new ArrayList<ProfessionDSA>();
			for (EntityWeighted entityWeighted : allEntities) {
				if (entityWeighted.getEntity() instanceof ProfessionDSA) {
					ProfessionDSA profession = (ProfessionDSA) entityWeighted.getEntity();
					professions.add(profession);
				}else{
					logger.error("Non-Culture provided: "+entityWeighted.getEntity());
				}
			}
			for (ProfessionDSA professionDSA : professions) {
				if(selectedProfession.equals(professionDSA.getName())){
					changedPerson.setProfession(UUIDReference.extractUUIDReference(professionDSA));
					updatePossibleRCP(changedPerson);
					break;
				}
			}
			logger.error("PROFESSION "+selectedProfession+" not found");
		} catch (ProfessionNotFoundException e) {
			logger.error("no professions found, check configuration");
		}
	}



	public CompositePersonBaseDSA getComposite() {
		return composite;
	}

	public void setComposite(CompositePersonBaseDSA composite) {
		removeUIListeners(this.composite);
		this.composite = composite;
		initalizeComposite();
		addUIListeners(this.composite);
	}

	public PersonBaseDSA getPerson() {
		return changedPerson;
	}

	public void setPerson(PersonBaseDSA person) {
		try {
			removeModelListeners(this.changedPerson);
			this.originalPerson = (PersonBaseDSA) person.clone();
			this.changedPerson = person;
			addModelListeners(this.changedPerson);
		} catch (CloneNotSupportedException e) {
			logger.error("person cloning not possible",e);
		}
	}
	//TODO check if this could be injected better
	public void setRCPFinder(IServiceDSARCPFinder rcpFinder) {
		if (this.rcpFinder.equals(rcpFinder)) {
			return;
		}
		this.rcpFinder = rcpFinder;
	}
	//TODO check if this could be injected better
	public void setProviderMonths(IServiceDSAProviderMonths providerMonths) {
		if (this.providerMonths.equals(providerMonths)) {
			return;
		}
		this.providerMonths = providerMonths;
	}


	protected PersonBasePCL modelListener = new PersonBasePCL();
	protected class PersonBasePCL implements PropertyChangeListener{
		@Override
		public void propertyChange(PropertyChangeEvent evt) {
			if (evt instanceof IndexedPropertyChangeEvent) {
				IndexedPropertyChangeEvent idx_Event = (IndexedPropertyChangeEvent) evt;
				updatePropertyInView(idx_Event.getIndex(),idx_Event.getNewValue());
			}
		}
	}

	protected PersonBaseUIL personBaseUIL = new PersonBaseUIL();
	protected class PersonBaseUIL implements ActionListener{
		@Override
		public void actionPerformed(ActionEvent event) {
			// event holds property in id and event in command
			int property = event.getID(); //FIXME make own listener/event to transport data cbf.util.ui
//			String command = event.getActionCommand();//Selection/Modify .. not necessary at the moment
			switch (property) {
//			case CompositePersonBaseDSA.ID_TITLE:
//				changeTitle(composite.getTitle());
//				break;
//			case CompositePersonBaseDSA.ID_FIRST_NAME:
//				changeFirstName(composite.getFirstName());
//				break;
//			case CompositePersonBaseDSA.ID_NAME_ADD:
//				changeNameAdd(composite.getNameAdd());
//				break;
//			case CompositePersonBaseDSA.ID_SUR_NAME:
//				changeSurName(composite.getSurName());
//				break;
			case CompositePersonBaseDSA.ID_BIRTH_DAY:
				changeBirthDay(composite.getSelectedBirthDay());
				break;
			case CompositePersonBaseDSA.ID_BIRTH_MONTH:
				changeBirthMonth(composite.getSelectedMonth());
				break;
			case CompositePersonBaseDSA.ID_BIRTH_YEAR:
				changeBirthYear(composite.getBirthYear());
				break;
			case CompositePersonBaseDSA.ID_HEIGTH:
				changeHeigth(composite.getHeigth());
				break;
			case CompositePersonBaseDSA.ID_WEIGHT:
				changeWeight(composite.getWeight());
				break;
			case CompositePersonBaseDSA.ID_RACE:
				changeRace(composite.getSelectedRace());
				break;
			case CompositePersonBaseDSA.ID_CULTURE:
				changeCulture(composite.getSelectedCulture());
				break;
			case CompositePersonBaseDSA.ID_PROFESSION:
				changeProfession(composite.getSelectedProfession());
				break;
			case CompositePersonBaseDSA.ID_EYES:
				changeWeight(composite.getWeight());
				break;
			case CompositePersonBaseDSA.ID_HAIR:
				changeWeight(composite.getWeight());
				break;
			case CompositePersonBaseDSA.ID_CHARACTER_SPECIALS:
				openCharacterSpecialWindow();
				break;
			case CompositePersonBaseDSA.ID_LOOKS:
				openLooksWindow();
				break;
			default:
				logger.error("unknown event type encountered:" +property);
				break;
			}
		}
	}



}
